package calcul;

import generatepath.CableTypeLengthValuesPair;

import java.util.ArrayList;
import java.util.StringTokenizer;

import org.apache.commons.collections.map.MultiKeyMap;

public class CalculatePVV {
	public ArrayList<Dictionar> calculate(ArrayList<String> paths, MultiKeyMap multiKeyMapCableTypeLength) {
		
		ArrayList<Dictionar> rasp = new ArrayList();
		for (String path : paths) {
			int counter = 0, tokenLength;
			StringTokenizer str = new StringTokenizer(path, ";");
			tokenLength = str.countTokens();
			String initial = str.nextToken();
			double totalPVV = 0;
			while (str.hasMoreTokens()) {
				String curent = str.nextToken();
				CableTypeLengthValuesPair temp = (CableTypeLengthValuesPair) multiKeyMapCableTypeLength.get(initial, curent);
				if (counter == 0) {
					totalPVV += temp.getValue().getPvvS();
				} else if (counter == tokenLength - 2) {

				} else {
					totalPVV += temp.getValue().getPvvI();
				}
				counter++;
				initial = curent;
			}
			rasp.add(new Dictionar(path, totalPVV));
		}
		
		return rasp;
		
	}
}
